﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HandmadeShop.BusinessLogic.Utilities
{
    public sealed class Helper
    {
        private static volatile Helper instance;
        private static object synRoot = new object();

        private Helper() { }

        public static Helper Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (synRoot)
                    {
                        if (instance == null)
                            instance = new Helper();
                    }
                }

                return instance;
            }
        }

        public string Encrypt(string text)
        {
            return this.SHA1(text);
        }

        private string SHA1(string text)
        {
            var hash = System.Security.Cryptography.SHA1.Create();
            var encoder = new ASCIIEncoding();
            var combined = encoder.GetBytes(text ?? "");

            string encrypt = BitConverter.ToString(hash.ComputeHash(combined)).ToLower().Replace("-", "");
            return encrypt;
        }
    }
}
